home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj8403.arc / EX4ADV.ASM next >
Assembly Source File  |  1984-01-31  |  5KB  |  163 lines

  1. ; ROUTINES FOR CHAPTER 7 - GRAPHICS - ADVANCED FUNCTIONS
  2. ;
  3. ; For 320 x 200 color graphics mode
  4. ;
  5.         extrn   setpt:far,xorpt:far,locate:far
  6.         extrn   setbox:far,xorbox:far
  7.         extrn   x0:word,y0:word,x1:word,y1:word,x2:word,y2:word
  8.         extrn   color:word
  9.         extrn   ptable:word
  10. ;
  11. ;*********************************************************
  12. stacks  segment stack
  13.         db      100 dup('paint stack     ')
  14. paintstack      label   word
  15.         db      100 dup('regular stack   ')
  16. stacks  ends
  17. ;*********************************************************
  18. datas   segment public
  19. ;
  20.         public  font
  21.         public  xmagn,ymagn
  22.         public  xmess,ymess
  23. ;
  24. ; public parameters
  25. font    db      0
  26. xmagn   db      1
  27. ymagn   db      1
  28. xmess   dw      ?
  29. ymess   dw      ?
  30. ;
  31. ; parameters needed for line drawing routine
  32. dels    dw      ?
  33. delp    dw      ?
  34. dele    dw      ?
  35. ;
  36. deltas  label   word
  37. delsx   dw      ?
  38. delsy   dw      ?
  39. delse   dw      ?
  40. deldx   dw      ?
  41. deldy   dw      ?
  42. delde   dw      ?
  43. ;
  44. datas   ends
  45. ;**********************************************************
  46. video   segment at 0B800h
  47. video   ends
  48. ;**********************************************************
  49. ex4adv  segment
  50. ;
  51.         public  gmessout
  52.         public  setline
  53.         public  schar,rchar
  54.         public  paint
  55. ;
  56.         assume  cs:ex4adv,ds:datas,es:video,ss:stacks
  57. ;
  58. ;----------------------- routine begins ------------------------------+
  59. ; ROUTINE TO DRAW LINE
  60. ;
  61. setline proc    far
  62.         push    bx              ; save registers
  63.         push    cx
  64.         push    dx
  65.         push    si
  66.         push    di
  67.         push    ax
  68. ;
  69. ; set up x and y updates
  70.         mov     si,1            ; start with positive 1 for x update
  71.         mov     di,1            ; start with positive 1 for y updats
  72. ;
  73. ; find |y2-y1|
  74.         mov     dx,y2           ; get y2
  75.         sub     dx,y1           ; subtract y1
  76.         jge     storey          ; skip if y2-y1 is nonegative
  77.         neg     di              ; move in negative y direction
  78.         neg     dx              ; absolute value of y2-y1
  79. storey:
  80.         mov     deldy,di        ; store y update for diagonal moves
  81. ;
  82. ; find |x2-x1|
  83.         mov     cx,x2           ; get x2
  84.         sub     cx,x1           ; subtract x1
  85.         jge     storex          ; skip if x2-x1 is nonnegative
  86.         neg     si              ; move in negative x direction
  87.         neg     cx              ; absolute value of x2-x1
  88. storex:
  89.         mov     deldx,si        ; store x update for diagonal moves
  90. ;
  91. ; sort |y2-y1| and |x2-x1|
  92.         cmp     cx,dx           ; compare  dels with delp
  93.         jge     setdiag         ; skip if straight moves in x direction
  94.         mov     si,0            ; if straight=vertical: kill x update
  95.         xchg    cx,dx           ;    and exchange differences
  96.         jmp     storedelsxy
  97. ;
  98. setdiag:
  99.         mov     di,0            ; if straight=horizontal: kill y update
  100. ; store dels, delp, delsx, and delsy
  101. storedelsxy:
  102.         mov     dels,cx         ; change in straight direction
  103.         mov     delp,dx         ; change in perpendicular to straight
  104.         mov     delsx,si        ; x update in straight direction
  105.         mov     delsy,di        ; y update in straight direction
  106. ;
  107. ; get initial values for x and y
  108.         mov     si,x1           ; x-coordinate
  109.         mov     di,y1           ; y-coordinate
  110. ;
  111. ; compute initial value and increments for error function
  112.         mov     ax,delp
  113.         sal     ax,1            ; 2*delp
  114.         mov     delse,ax        ; change if straight move
  115. ;
  116.         sub     ax,cx           ; 2*delp - dels
  117.         mov     bx,ax           ; initial value
  118. ;
  119.         sub     ax,cx           ; 2*delp - 2*dels
  120.         mov     delde,ax        ; change if diagonal move
  121. ;
  122. ; adjust count
  123.         inc     cx
  124. ;
  125. ; set the color
  126.         mov     dx,color        ; get the color
  127. ;
  128. ; main loop structure
  129. lineloop:
  130.         call    setpt           ; plot the point
  131.         cmp     bx,0            ; determine straight or diagonal move
  132.         jge     diagonal
  133. ;
  134. ; case for straight move
  135. straight:
  136.         add     si,delsx        ; update x
  137.         add     di,delsy        ; update y
  138.         add     bx,delse        ; update error term
  139.         loop    lineloop        ; next point
  140.         jmp     lineexit
  141. ;
  142. ; case for diagonal move
  143. diagonal:
  144.         add     si,deldx        ; update x
  145.         add     di,deldy        ; update y
  146.         add     bx,delde        ; update error term
  147.         loop    lineloop        ; next point
  148. ;
  149. lineexit:
  150.         pop     ax              ; restore registers
  151.         pop     di
  152.         pop     si
  153.         pop     dx
  154.         pop     cx
  155.         pop     bx
  156.         ret
  157. ;
  158. setline endp
  159. ;----------------------- routine ends --------------------------------+
  160. ex4adv  ends                    ; end of code segment
  161. ;
  162.         end
  163.